package handler

import (
	"gluenet/pkg/apis"
)

//var head *http.Header
//var once sync.Once
//
//func getHeader() http.Header {
//	once.Do(func() {
//		head = &http.Header{}
//		head.Add("Content-Encoding", "snappy")
//		head.Set("Content-Type", "application/x-protobuf")
//		head.Set("User-Agent", fmt.Sprintf("Prometheus/%s", version.Version))
//		head.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
//	})
//
//	return *head
//}

func Metrics(ctx *apis.StorageContext) {
	//ctx.Logger.Debugf("REQ metrice push")
	//return
	//ctx.Logger.Debugf(fmt.Sprintf("%v/api/v1/prom/write?impl=prometheus", ctx.Env["INFLUXDB_URL"]))

	//httpReq, err := http.NewRequest("POST", ctx.PrometheusUrl, bytes.NewReader(ctx.RpcContext.Data.Data))
	//if err != nil {
	//	ctx.Logger.Errorf("new request failed")
	//	return
	//}
	//httpReq.Header = getHeader()

	if err := ctx.DataBase.MetricsPut(ctx.RpcContext.Data.Data); err != nil {
		ctx.Logger.Errorf("write data failed %v", err)
		return
	}

	ctx.MetricsChan <- ctx.RpcContext.Data.Data
}
